package com.hushao.aimi.repository;

import com.hushao.aimi.entity.AimiProduct;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ProductRespository extends JpaRepository<AimiProduct,String> {


    @Query(value = "SELECT p.id as productId,p.name AS productName,r.recommend_image  " +
            "FROM aimi_recommend r  LEFT JOIN aimi_product p on p.id =r.product_id " +
            "LEFT JOIN aimi_category c ON c.id =p.category_id  \n " +
            "where p.category_id = :categoryId And p.status = :productStatus " +
            "And r.recommend_status = :recommendStatus And  r.recommend_code = :recommendCode "+
            "ORDER BY r.sort_order",nativeQuery = true)
    List<Object> listCategoryAndProduct(@Param("categoryId") Integer categoryId,
                                           @Param("productStatus") int productStatus,
                                           @Param("recommendStatus") int recommendStatus,
                                           @Param("recommendCode") String recommendCode);
}
